# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=swayimg
pkgver=1.7
pkgrel=1
pkgdesc="Image viewer for Sway"
url="https://github.com/artemsen/swayimg"
arch="all"
license="MIT"
makedepends="
	bash-completion
	cairo-dev
	giflib-dev
	json-c-dev
	libavif-dev
	libexif-dev
	libjpeg-turbo-dev
	libjxl-dev
	libxkbcommon-dev
	meson
	wayland-dev
	wayland-protocols
	"
subpackages="
	$pkgname-full
	$pkgname-doc
	$pkgname-bash-completion
	"
source="https://github.com/artemsen/swayimg/archive/v$pkgver/swayimg-$pkgver.tar.gz"
options="!check"  # no tests provided

case "$CARCH" in
	riscv64 | s390x) _librsvg='disabled';;  # librsvg is not available
	*) _librsvg='enabled'; makedepends="$makedepends librsvg-dev";;
esac

build() {
	msg 'Building basic variant'
	_build output \
		-Davif=disabled \
		-Djxl=disabled \
		-Dsvg=disabled

	msg 'Building full variant'
	_build output-full \
		-Dbash=disabled \
		-Dman=false
}

_build() {
	local outdir=$1; shift

	abuild-meson \
		-Davif=enabled \
		-Dgif=enabled \
		-Djpeg=enabled \
		-Djxl=enabled \
		-Dpng=enabled \
		-Dsvg=$_librsvg \
		-Dwebp=disabled \
		-Dexif=enabled \
		-Dbash=enabled \
		-Dversion=$pkgver \
		"$@" \
		. "$outdir"
	meson compile -j ${JOBS:-0} -C "$outdir"
}

package() {
	pkgdesc="$pkgdesc - with support for basic formats"
	provider_priority="100"  # highest (other provider is swayimg-full)

	DESTDIR="$pkgdir" meson install --no-rebuild -C output
	install -D -m644 extra/swayimgrc "$pkgdir"/etc/xdg/$pkgname/config
}

full() {
	pkgdesc="$pkgdesc - with support for all formats"
	provides="$pkgname=$pkgver-r$pkgrel"
	provider_priority="10"  # lowest (other provider is swayimg)

	cd "$builddir"

	DESTDIR="$subpkgdir" meson install --no-rebuild -C output-full
	install -D -m644 extra/swayimgrc "$subpkgdir"/etc/xdg/$pkgname/config
}

sha512sums="
e4e61eae6406a278961b00fed1bccfe060043251685e955428d0a4f0ce3cd5420d6b4e12415e998deb906e1eaaf68a13d28223928d5247299eb6d0333fec083d  swayimg-1.7.tar.gz
"
